#ifndef __SI12TCH_IIC_H
#define __SI12TCH_IIC_H

#include "stm32f0xx.h"                  // Device header

#include "delay.h"

//IIC_EN PB2
#define SI12TCH_IIC_EN  GPIO_ResetBits(GPIOB,GPIO_Pin_2);
#define SI12TCH_IIC_OFF GPIO_SetBits(GPIOB,GPIO_Pin_2);

//IIC_SCT PF8
#define SI12TCH_SCT_SET GPIO_SetBits(GPIOF,GPIO_Pin_7);
#define SI12TCH_SCT_RESET GPIO_ResetBits(GPIOF,GPIO_Pin_7);

//SDA IO方向设置
#define SI12TCH_I2C_SDA_IN()  SI12TCH_sda_mode(0);
#define SI12TCH_I2C_SDA_OUT() SI12TCH_sda_mode(1);


/* 软件模拟 I2C */
#define SI12TCH_I2C_SCL_1()  GPIO_SetBits(GPIOB,GPIO_Pin_6);				/* SCL = 1 */
#define SI12TCH_I2C_SCL_0()  GPIO_ResetBits(GPIOB,GPIO_Pin_6);				/* SCL = 0 */
#define SI12TCH_I2C_SDA_1()  GPIO_SetBits(GPIOB,GPIO_Pin_7);				/* SDA = 1 */
#define SI12TCH_I2C_SDA_0()  GPIO_ResetBits(GPIOB,GPIO_Pin_7);			/* SDA = 0 */
#define SI12TCH_I2C_SDA_READ()  (GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_7) != 0)	/* 读SDA口线状态 */

#define SI12TCH_FLAG_TIMEOUT ((int)0xff)
#define SI12TCH_LONG_TIMEOUT ((int)(10 * SI12TCH_FLAG_TIMEOUT))




void SI12TCH_sda_mode(uint8_t mode);
void si12tch_i2c_Delay(void);	//延时
void si12tch_iic_Init(void);	//初始化
void si12tch_i2c_Start(void);	//发送IIC开始信号
void si12tch_i2c_Stop(void);	//发送IIC停止信号
unsigned char si12tch_i2c_WaitAck(void);		//IIC等待ACK信号
void si12tch_i2c_SendByte(unsigned char _ucByte); //IIC发送一个字节
unsigned char si12tch_i2c_ReadByte(uint8_t ack); 	//IIC读取一个字节
void si12tch_i2c_Ack(void);			//IIC发送ACK信号
void si12tch_i2c_NAck(void);	//IIC发送NAck信号


#endif
